package visual;
 
/*
 * TableDemo.java requires no other files.
 */
 
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.util.ArrayList;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;

import creatures.ICreature;
 
/** 
 * TableDemo is just like SimpleTableDemo, except that it
 * uses a custom TableModel.
 */
@SuppressWarnings("serial")
public class StatisticTable extends JFrame {
	
	/**
	 * The table model
	 */
	private StatisticTableModel statTable;
 
    public StatisticTable(ArrayList<? extends ICreature> creatures, ArrayList<String> pluginNames) {
        super("Statistiques");
        setLayout(new BorderLayout());
        JPanel pan = new JPanel();
        
        this.statTable = new StatisticTableModel(creatures,pluginNames);
        
        JTable table = new JTable(this.statTable);
        table.setPreferredScrollableViewportSize(new Dimension(500, 70));
        table.setFillsViewportHeight(true);
        
        this.setSize(new Dimension(500,100));
        this.setLocation(640,0);
        this.setResizable(false);
        
        pan.add(table);
        
        //Create the scroll pane and add the table to it.
        JScrollPane scrollPane = new JScrollPane(table);
 
        //Add the scroll pane to this panel.
        pan.add(scrollPane);
        
        add(pan,BorderLayout.CENTER); 
        setDefaultCloseOperation(HIDE_ON_CLOSE);
		pack();
    }
    
   /**
    * Refreshes the table model
    * {@link StatisticTableModel}
    * 
    * @param creatures
    */
   public void refreshModel(ArrayList<? extends ICreature> creatures) {
	   this.statTable.refreshCreatures(creatures);
   }
   
   /**
    * Gets the attribut "pluginName" in the table model
    * {@link StatisticTableModel}
    * 
    * @return
    */
   public ArrayList<String> getPluginNames() {
	   return this.statTable.getPluginNames();
   }
   
   /**
    * Gets the attribut "creaturesData" in the table model
    * {@link StatisticTableModel}
    * 
    * @return
    */
   public ArrayList<ArrayList<Integer>> getCreaturesDatas() {
	   return this.statTable.getCreaturesDatas();
   }
   
   /**
    * Increases the birth counter of the creature in the table model
    * {@link StatisticTableModel}
    * 
    * @param creature
    */
   public void increaseBirth(ICreature creature) {
	   this.statTable.increaseBirth(creature);
   }
}